;(function(window){
	function Mscroll(options){
		this.touchContainer = document.getElementById(options.container);
		this.pulldownText = document.getElementById(options.pulldownText);
		this.refreshText = "下拉刷新...";
		this.refreshingText =  "松手刷新...";
		this.loadText="下拉加载更多...";
		this.loadingText = "松手加载更多...";
		this.touchStartY = 0; //触摸时y轴坐标	
		this.touchHeight = 0;//下拉的高度
		this.options = options;
		//初始化
		this.init();
	}

	//添加原型方法
	Mscroll.prototype = {
		touchStartEvent:function(){//触摸开始事件
			var _this = this;
			_this.touchContainer.addEventListener('touchstart',function(e){
				var e = e || window.event;
				_this.touchStartY = e.touches[0].pageY; //获取触摸时的y位置	

				//设置触摸容易所需Css 样式
			_this.touchContainer.style.position = "relative";
			_this.touchContainer.style.transition = "transform 0s";
			_this.pulldownText.style.transition = "transform 0s";
			})	
		},
		touchMoveEvent:function(){//触摸滑动事件
			var _this = this;
			_this.touchContainer.addEventListener('touchmove',function(e){
				_this.touchHeight = e.touches[0].pageY - _this.touchStartY;
				var e = e || window.event;
				//根据下拉的位置判断，当距离在0 - 50 px 显示 下拉加载更多， 60以上 显示松手显示更多
				if(_this.touchHeight > 0 && _this.touchHeight <= 50){
					_this.pulldownText.innerHTML = _this.refreshText;
				}else if(_this.touchHeight > 50 ){
					_this.pulldownText.innerHTML = _this.refreshingText;
					_this.pulldownText.style.top = _this.touchHeight - 50 +'px';//设置下拉跟着显示
				}
				//显示下拉
				_this.touchContainer.style.transform = 'translateY('+_this.touchHeight+'px)';
			})	
		},
		touchEndEvent:function(){
			var _this = this;	
			_this.touchContainer.addEventListener('touchend',function(){
				_this.touchContainer.style.transition = "transform 0.5s ease 1s";
				_this.touchContainer.style.transform = "translateY(50px)";
				_this.pulldownText.innerHTML = '正在刷新...';
				_this.pulldownText.style.transition = "top 0.5s ease 1s";
				_this.pulldownText.style.top = 0;

				//需要做的事情
				_this.options.scrollDown();
			})
		},
		init:function(){
			this.touchStartEvent();//绑定触摸开始事件
			this.touchMoveEvent();//绑定触摸移动事件
			this.touchEndEvent();//绑定触摸结束事件
		}
	}

	//将构造函数添加到window 提供使用
	window.Mscroll = Mscroll;
})(window)